//
//  ViewController.m
//  MutlThreads
//
//  Created by 赵梁 on 2017/2/14.
//  Copyright © 2017年 赵梁. All rights reserved.
//

#import "ViewController.h"

#import "CGDTest.h"
#import "OperationTest.h"
#import "RunLoopTest.h"
@interface ViewController ()

@property (nonatomic, strong) NSArray* dataSource;//!< <#描述#>
@property (nonatomic, strong) CGDTest* gcd;//!< <#描述#>

@property (nonatomic, strong) OperationTest* operation;//!< 描述

@property (nonatomic, strong) RunLoopTest* runloop;//!< 描述

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
//    [self.gcd runTest];
//    [self.gcd testBody];
//    [self.gcd barrier];
//    [self.gcd apply];
//    [self.gcd group];
    
//    [self.operation mainQueue];
//    [self.operation otherQueue];
//    [self.operation serailQueue];
//    [self.operation addDependency];
    
    [self.runloop timerRunInDefaultRunLoopMode];
    [self.runloop timerRunInUITrackingRunLoopMode];
    [self.runloop timerRunInNSRunLoopCommonModes];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *dic = self.dataSource[indexPath.row];
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MTCell"];
    cell.textLabel.text = dic[@"title"];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *dic = self.dataSource[indexPath.row];
    [self.gcd testDispatchQueue:[dic[@"queue_type"] integerValue] isAsync:[dic[@"async"] boolValue]];
}

- (NSArray *)dataSource
{
    if (!_dataSource) {
        _dataSource = @[
                        @{@"title":@"并行队列 + 同步",@"queue_type":@"1",@"async":@(NO),},
                        @{@"title":@"并行队列 + 异步",@"queue_type":@"1",@"async":@(YES),},
                        @{@"title":@"串行队列 + 同步",@"queue_type":@"0",@"async":@(NO),},
                        @{@"title":@"串行队列 + 异步",@"queue_type":@"0",@"async":@(YES),},
                        @{@"title":@"主队列 + 同步",@"queue_type":@"2",@"async":@(NO),},
                        @{@"title":@"主队列 + 异步",@"queue_type":@"2",@"async":@(YES),},
                        ];
    }
    return _dataSource;
}

- (CGDTest *)gcd
{
    if (!_gcd) {
        _gcd = [CGDTest new];
    }
    return _gcd;
}

- (OperationTest *)operation
{
    if (!_operation) {
        _operation = [OperationTest new];
    }
    return _operation;
}

- (RunLoopTest *)runloop
{
    if (!_runloop) {
        _runloop = [RunLoopTest new];
    }
    return _runloop;
}

@end
